package go84.util;

import go84.UTM;

public class Util {
	public static String hebString(String str) {
		String strTemp = "";
		String strDisp = "";
		for (int i = str.length() - 1; i >= 0; i--) {
			if (str.charAt(i) > 1400) {
				strDisp = strDisp + strTemp + str.charAt(i);
				strTemp = "";
			} else {
				strTemp = str.charAt(i) + strTemp;
			}
		}
		strDisp = strDisp + strTemp;
		return strDisp;
	}
	
	
    public static double[] dtmConv(double oldLong, double oldLat, double oldAlt, UTM.Datum from, UTM.Datum to) {
        double /*oldLat, oldLong, oldAlt,*/ lat, lon, alt;//, merid;
        double oldX, oldY, oldZ, x, y, z, oldV, v;
        double Deg2Rad = Math.PI / 180.0;
        /*oldLat=old.getLatitude();
        oldLong=old.getLongitude();
        if (!Float.isNaN(old.getAltitude())) {
            oldAlt=old.getAltitude();
        }
        else {
            oldAlt=0;
        }*/
        //merid=Math.floor((oldLong)/6)*6+3;
        oldV=from.a/Math.sqrt(1-from.e2*Math.sin(oldLat*Deg2Rad)*Math.sin(oldLat*Deg2Rad));
        oldX=(oldV+oldAlt)*Math.cos(oldLat*Deg2Rad)*Math.cos(oldLong*Deg2Rad);
        oldY=(oldV+oldAlt)*Math.cos(oldLat*Deg2Rad)*Math.sin(oldLong*Deg2Rad);
        oldZ=((1-from.e2)*oldV+oldAlt)*Math.sin(oldLat*Deg2Rad);
        x=oldX+to.dx-from.dx;
        y=oldY+to.dy-from.dy;
        z=oldZ+to.dz-from.dz;
        lat=UTM.atan((z+to.e2*oldV*Math.sin(oldLat*Deg2Rad))/Math.sqrt(x*x+y*y))/Deg2Rad;
        v=to.a/Math.sqrt(1-to.e2*Math.sin(lat*Deg2Rad)*Math.sin(lat*Deg2Rad));
        lat=UTM.atan((z+to.e2*v*Math.sin(lat*Deg2Rad))/Math.sqrt(x*x+y*y))/Deg2Rad;
        lon=UTM.atan(y/x)/Deg2Rad;
        alt=x/(Math.cos(lat*Deg2Rad)*Math.cos(lon*Deg2Rad))-v;
        //Coordinates res=new Coordinates(lat, lon, (float)alt);
        double[] res =new double[3];
        res[0]=lon; res[1]=lat; res[2]=(float)alt;
        return res;
    }
}
